<?php
/**
 * Created by PhpStorm.
 * User: ybjaa
 * Date: 2017/6/20
 * Time: 14:11
 */

namespace database\model;


use App\Units;

class GetModels
{


    //获得基本表(不包含日志表和业务表)
    static public function GetBaseModels()
    {
        $array=Units::getFilePath(__DIR__);

        $prefix=(new \ReflectionClass(base::class))->getNamespaceName();


        //映射为ReflectionClass对象
        $array=array_map(function ($a) use ($prefix) {
            return new \ReflectionClass($prefix.str_replace("//","\\",str_replace([__DIR__,".php"],"",$a)));
        },$array);

        //判断是否是子类以及非抽象类
        $array=array_filter($array,function(\ReflectionClass $a){
            return $a->isSubclassOf(base::class) & !$a->isAbstract() & !$a->isSubclassOf(baseLog::class) & !$a->isSubclassOf(baseBusiness::class);
        });

        return array_map(function(\ReflectionClass $a){
            return $a->newInstance();
        },$array);
    }


    //获得日志表(不包含基础表和业务表)
    static public function GetBaseLogModels()
    {
        $array=Units::getFilePath(__DIR__);

        $prefix=(new \ReflectionClass(base::class))->getNamespaceName();


        //映射为ReflectionClass对象
        $array=array_map(function ($a) use ($prefix) {
            return new \ReflectionClass($prefix.str_replace("//","\\",str_replace([__DIR__,".php"],"",$a)));
        },$array);

        //判断是否是子类以及非抽象类
        $array=array_filter($array,function(\ReflectionClass $a){
            return $a->isSubclassOf(baseLog::class) & !$a->isAbstract();
        });

        return array_map(function(\ReflectionClass $a){
            return $a->newInstance();
        },$array);
    }


    //获得业务表(不包含基础表和日志表)
    static public function GetBaseBusinessModels()
    {
        $array=Units::getFilePath(__DIR__);

        $prefix=(new \ReflectionClass(base::class))->getNamespaceName();


        //映射为ReflectionClass对象
        $array=array_map(function ($a) use ($prefix) {
            return new \ReflectionClass($prefix.str_replace("//","\\",str_replace([__DIR__,".php"],"",$a)));
        },$array);

        //判断是否是子类以及非抽象类
        $array=array_filter($array,function(\ReflectionClass $a){
            return $a->isSubclassOf(baseBusiness::class) & !$a->isAbstract();
        });

        return array_map(function(\ReflectionClass $a){
            return $a->newInstance();
        },$array);
    }

}